class Solution {
public:
    int lengthOfLongestSubstring(string s)
    {
        int left = 0, right = 0;
        int hash[128] = { 0 };
        int maxlen = 0;
        while (s.size() > right)
        {
            hash[s[right]]++;
            while (hash[s[right]] > 1)
            {
                hash[s[left]]--;
                left++;
            }
            maxlen = max(maxlen, right - left + 1);

            right++;
        }
        return maxlen;
    }
};